<template>
	<view class="content">
		<view style="height: 40rpx;"></view>
		<view class="wid90 mar bacFFF borRad20">
			<view class="wid90 mar hei80 dis disAl">
				<view class="foSi30" style="width: 30%;">到账账户：</view>
				<view class="foSi40" style="width: 70%;" v-if="userinfo.system_type == 1">{{userinfo.bank_num}}</view>
				<view class="foSi40" style="width: 70%;color:green" v-if="userinfo.system_type == 2">微信零钱</view>
			</view>
			<view class="xhx"></view>
			<view class="wid90 mar hei80 dis disAl">
				<view class="foSi30" style="width: 30%;">提现金额：</view>
				<view class="foSi30 dis disAl" style="width: 70%;">
					<view>￥</view>
					<input class="foSi40" style="color: #1262DB;" type="number" :value="money" @input="onKeyInput" />
				</view>
			</view>
			<view class="xhx"></view>
			
			<view class="wid90 mar hei60 dis disAl foSi20" style="color: #939292;">{{types == 1 ? '收益钱包' : '押金钱包'}}余额 ¥{{types == 1 ? parseFloat(income).toFixed(2) : parseFloat(userinfo.rea_money).toFixed(2)}}</view>
			<view style="height: 86rpx;margin-top: 50rpx;background-color: #1262DB;" 
				class="wid90 mar dis disAl disJuC borRad20 coFFF" @click="tixian">提现</view>
			<view style="height: 40rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tx: 0,
				income: '',
				money:0,
				userinfo: '',
				types:''
			}
		},
		
		onLoad(options) {
			this.types = options.types
			this.tx = options.tx
			this.getuserinfo()
			this.wallet()
		},
		methods: {
			wallet(){
				var that = this
				uni.request({
				    url: that.global.url + 'api/wallet/wallet',
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							that.income = result.data.income
						}else{
				           uni.showToast({
				           	title: result.msg,
				           	icon: 'error'
				           })
				        }
				       
				    }
				})
			},
			getuserinfo(){
				var that = this
				uni.request({
				    url: that.global.url + 'api/user/getuserinfo',
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							that.userinfo = result.data
						}else{
				           uni.showToast({
				           	title: result.msg,
				           	icon: 'error'
				           })
				        }
				       
				    }
				})
			},
			onKeyInput: function(e){
				this.money = e.target.value
			},
			tixian(){
				var that = this
				if(!that.money || that.money == 0){
					return
				}
				var urls = '';
				if(uni.getStorageSync('userinfo').system_type == 1){
					urls = 'api/wallet/initiate_withdrawal';
				}else{
					urls = 'api/wallet/new_initiate_withdrawal';
				}
				uni.request({
				    url: that.global.url + urls,
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						money: that.money,
						types:that.types
					},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							uni.showToast({
								title: '已发起提现',
							})
							that.wallet()
							that.getuserinfo()
						}else{
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
				        }
				       
				    }
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #1262DB;
	}
	
</style>
